The purpose of this segment is to share some of our favorite tools for working with data in R. We will focus on packages that are less popular than the Greatest of All Times (e.g. tidyverse and its associated ggplot2, dplyr, tidyr, etc.) though we highly encourage you to check these out!
here: no more getting lost in file pathsUse this package
when…all the time. Make it a part of your regular coding routine. It’s that good.
As we introduced in the previous module, here is an excellent package that’s worth getting to know because it will let you use relative as opposed to absolute pathnames. This will simplify importing and exporting files as well as sharing them with others.
install.packages("here")
library(here)
## here() starts at C:/Users/sbrei/Documents/R_Projects/Collabs/BGSS_Retreat_2021
here::here() # once you call the package with the library(here) call, you can use this function to remind you where your project root begins.
## [1] "C:/Users/sbrei/Documents/R_Projects/Collabs/BGSS_Retreat_2021"
revisit “here” package description
Artwork by Allison Horst. set_wd, be gone!
magrittr: these pipes will make your work flowUse this package when…
install.packages("magrittr")
library(magrittr)
patchwork: make your figures nice and cozyUse this package when…
install.packages("patchwork")
library(patchwork)
performance: evaluate your general linear models in a flashUse this package when…
install.packages("performance")
library(performance)
annotater: finally remember why you loaded all those packages!Use this package when… you forget why you loaded packages at the top of your R script/notebook/markdown file OR you want to clarify why you did so for collaborators. (+1 points for reproducible science!)
It happens: you start your R file with a list of packages to be loaded with your library call. You constantly add to it, listing more packages who functions you use to complete your analysis. Over time, you figure out that your advisors would prefer if you didn’t use the Wes Anderson color palette, or that you’re better off creating figures with patchwork vs cowplot (sorry, cowplot). So, if you’re anything like me, after learning stats and R simultaneously while doing your first thesis project, you end up with a very impressive list of R packages, half of which you can’t remember why you loaded in the first place.
Have no fear! This is where the genius of the annotater package comes in to save us (and those who try to read our code, bless them)!
install.packages("remotes")
remotes::install_github("luisDVA/annotater")
After you’ve installed remotes and annotater, save your R files, close RStudio, and reopen it.
Click anywhere in the Source pane (aka the one with your R files).
Navigate your cursor to the “Addins” button in the bar below the File-Edit-Code-View etc. bar. Click it and select, “Annotate package calls in active file”. Voila!
Please take 5 minutes and give us some feedback about today’s workshop- we’d be so grateful! Check out the “Feedback Page” link below. Thanks!